﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;

namespace Mimoza.RdpPlugin
{
    public partial class LocalResourcesPage : Mimoza.GUI.WizardPage
    {
        private RdpData m_data;

        public LocalResourcesPage()
        {
            InitializeComponent();
        }

        override public void Init()
        {
            m_data = this.Wizard.UserData as RdpData;

            comboBoxSound.SelectedIndex = (int)m_data.Sound;
            comboBoxKeyboard.SelectedIndex = (int)m_data.Keyboard;
            FillDevices(m_data.UsingDevice);

            this.comboBoxSound.SelectedIndexChanged += new System.EventHandler(this.comboBoxSound_SelectedIndexChanged);
            this.comboBoxKeyboard.SelectedIndexChanged += new System.EventHandler(this.comboBoxSound_SelectedIndexChanged);
            this.checkBoxSmartCard.CheckedChanged += new System.EventHandler(this.checkBoxDiskDrives_CheckedChanged);
            this.checkBoxSerialPorts.CheckedChanged += new System.EventHandler(this.checkBoxDiskDrives_CheckedChanged);
            this.checkBoxPrinters.CheckedChanged += new System.EventHandler(this.checkBoxDiskDrives_CheckedChanged);
            this.checkBoxDiskDrives.CheckedChanged += new System.EventHandler(this.checkBoxDiskDrives_CheckedChanged);
        }
        override public bool Try2LeavePage(WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Back)
            {
                return true;
            }

            m_data.Sound = (Sound)comboBoxSound.SelectedIndex;
            m_data.Keyboard = (Keyboard)comboBoxKeyboard.SelectedIndex;
            m_data.UsingDevice = GetDevices();

            return true;
        }
        void FillDevices(Devices devices)
        {
            checkBoxDiskDrives.Checked = devices.UseDiskDrives;
            checkBoxPrinters.Checked = devices.UsePrinters;
            checkBoxSerialPorts.Checked = devices.UseSerialPorts;
            checkBoxSmartCard.Checked = devices.UseSmartCards;
        }
        Devices GetDevices()
        {
            Devices devices = new Devices();
            devices.UseDiskDrives = checkBoxDiskDrives.Checked;
            devices.UsePrinters = checkBoxPrinters.Checked;
            devices.UseSerialPorts = checkBoxSerialPorts.Checked;
            devices.UseSmartCards = checkBoxSmartCard.Checked;

            return devices;
        }

        private void comboBoxSound_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.IsConfigured = true;
            this.RaiseOnPageModified();
        }

        private void checkBoxDiskDrives_CheckedChanged(object sender, EventArgs e)
        {
            this.IsConfigured = true;
            this.RaiseOnPageModified();
        }
    }
}
